<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>消息中心</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="./layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="./layuiadmin/style/admin.css" media="all">
  <script type="text/javascript" src="lib/layui/layui.js" ></script>
  <script type="text/javascript" src="./js/global.js" ></script>
</head>
<body>

  <div class="layui-fluid" id="LAY-app-message">
    <div class="layui-card">
      <div class="layui-tab layui-tab-brief">
        <ul class="layui-tab-title">
          <li class="layui-this">全部消息</li>
        </ul>
        <div class="layui-tab-content">
        
          
            
            <table id="tab" lay-filter="table"></table>
          </div>
        </div>
      </div>
    </div>
  </div>
  
  <script type="text/html" id="top">
          	<button class="layui-btn layui-btn-primary layui-btn-sm" lay-event="del">删除</button>
          </script>
  <!--详情-->
			<div id="xqDiv" class="layui-form-item" style="margin-top: 10px; margin-left:10px;display: none;">
				<form id="xqForm" lay-filter="updateForm" class="layui-form" method="post" onsubmit="return false;">
					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">学生名称</label>
							<div class="layui-input-inline"style="width: 150px;">
								<input type="hidden" id="mid" disabled class="layui-input">
								<input type="text" id="name" disabled class="layui-input">
							</div>
						</div>
						
						
					</div>
					<div class="layui-form-item">
					<div class="layui-inline">
							<label class="layui-form-label">网络咨询：</label>
					          <div class="layui-input-inline" style="width: 150px;">
						           <input type="text" id="user" disabled class="layui-input">
						      </div>
						</div>
					</div>
					
					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">时间：</label>
					          <div class="layui-input-inline" style="width: 350px;">
						           <input type="text" id="time" disabled class="layui-input">
						      </div>
						     </div>
					</div>
					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">内容：</label>
					          <div class="layui-input-inline" style="width: 350px;">
						           <textarea id="msg" disabled class="layui-textarea"></textarea>
						      </div>
						     </div>
					</div>
				</form>
			</div>
  <script>
  	layui.use(["table","layer","form"],function(){
  		var table=layui.table;
  		var $=layui.$;
  		var layer=layui.layer;
  		var form=layui.form;
  		
  		table.render({
  			elem:"#tab",
  			url:globalData.server+"/msg/getMessage",
  			where:{'token':globalData.getCurToken(),"askerid":globalData.getCurUName()},
  			mothod:"post",
  			page:true,
  			toolbar:"#top",
  			parseData:function(res){
						  return{
							  "code":0,
							  "msg":"1",
							  "count":res.totalElements,
							  "data":res.content
						  }
					 },
					 cols:[[
					 {type:"checkbox"},
						{field:'msg',title:'内容'},
						{field:'status',title:'状态'},
						{field:'time',title:'时间'}
					]],
					id:"aaa"
  		})
  		
  		
  		//监听行单击事件（双击事件为：rowDouble）
			  table.on('rowDouble(table)', function(obj){
			  	$.post(globalData.server+"cx/findByUserId",{"uid":obj.data.userid,"token":globalData.getCurToken()},function(res){
			  		if(res!=null){
			  			$("#user").val(res);
			  		}
			  	})
			  	$.post(globalData.server+"cx/findByStuId",{"stuid":obj.data.stuid,"token":globalData.getCurToken()},function(a){
			  		if(a!=null){
			  			$("#name").val(a);
			  		}
			  	})
			  	$("#mid").val(obj.data.mid);
			  	$("#time").val(obj.data.time);
			  	$("#msg").val(obj.data.msg);
						layer.open({
							type: 1,
							title: '详情信息',
							content: $("#xqDiv"),
							area: ['550px', '500px'],
							end:function(){
								$.post(globalData.server+"/msg/upMessage",{"token":globalData.getCurToken(),"mid":obj.data.mid},function(r){
							if(r=0){
								layer.msg("修改失败");
							}else{
								parent.location.reload();
							}
						})
							}
						})
						
  	})
			  
			  var arr=[];
					table.on("toolbar(table)", function(obj) {
							var event = obj.event;
								var data = table.checkStatus("aaa").data;
							if(event == "del") {
								if(data.length < 1) {
									layer.msg("请选择需要删除的信息");
								} else {
									for(var i = 0; i < data.length; i++) {
										arr.push(data[i].mid);
									}
									layer.confirm('确定删除吗？',function(){
									$.post(globalData.server+"/msg/delMessage",{
										"token":globalData.getCurToken(),
										"ids":arr.join()
									},function(res){
										if(res>0){
											layer.msg("删除成功");
											location.reload();
										}else{
											layer.msg("删除失败");
										}
									})
									})
					}
								}
					})
  })	
  </script>
</body>
</html>